﻿using System;
using System.Net;

namespace network{
    public class IpAndName{
        public static void GetIpAndName(){
            DnsPermission dnsP=new DnsPermission(System.Security.Permissions.PermissionState.Unrestricted);
            dnsP.IsUnrestricted();
            string computerName = Dns.GetHostName();
            IPHostEntry myHost=new IPHostEntry();
//            myHost = Dns.Resolve(ComputerName);
            myHost = Dns.GetHostEntry(computerName);
            Console.WriteLine("本计算机的名称为:{0}", computerName);
            Console.WriteLine("本计算机的IP地址是:");
            for (int i = 0; i < myHost.AddressList.Length; i++) {
                Console.WriteLine("{0}", myHost.AddressList[i]);
            }
        }
    }
}